﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;

using DQYT.HTDZ.BLL;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.Web.FUJIAN
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    decimal ID = (Convert.ToDecimal(Request.Params["id"]));
                    ShowInfo(ID);
                }
            }
        }

        private void ShowInfo(decimal ID)
        {
            FUJIANBLL bll = new FUJIANBLL();
            FUJIANModel model = bll.GetModel(ID);
            this.lblID.Text = model.ID.ToString();
            this.txtATTACHID.Text = model.ATTACHID.ToString();
            this.txtOBJECTID.Text = model.OBJECTID.ToString();
            this.txtOBJECTTYPE.Text = model.OBJECTTYPE;
            this.txtATTACHNAME.Text = model.ATTACHNAME;
            this.txtATTACHURL.Text = model.ATTACHURL;
            this.txtATTACHTYPE.Text = model.ATTACHTYPE;
            this.txtATTACHBYTES.Text = model.ATTACHBYTES.ToString();
            this.txtATTACHSIZE.Text = model.ATTACHSIZE.ToString();
            this.txtUPLOADTIME.Text = model.UPLOADTIME.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (!PageValidate.IsDecimal(txtATTACHID.Text))
            {
                strErr += "ATTACHID格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtOBJECTID.Text))
            {
                strErr += "OBJECTID格式错误！\\n";
            }
            if (this.txtOBJECTTYPE.Text.Trim().Length == 0)
            {
                strErr += "OBJECTTYPE不能为空！\\n";
            }
            if (this.txtATTACHNAME.Text.Trim().Length == 0)
            {
                strErr += "ATTACHNAME不能为空！\\n";
            }
            if (this.txtATTACHURL.Text.Trim().Length == 0)
            {
                strErr += "ATTACHURL不能为空！\\n";
            }
            if (this.txtATTACHTYPE.Text.Trim().Length == 0)
            {
                strErr += "ATTACHTYPE不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtATTACHSIZE.Text))
            {
                strErr += "ATTACHSIZE格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtUPLOADTIME.Text))
            {
                strErr += "UPLOADTIME格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            decimal ID = decimal.Parse(this.lblID.Text);
            decimal ATTACHID = decimal.Parse(this.txtATTACHID.Text);
            decimal OBJECTID = decimal.Parse(this.txtOBJECTID.Text);
            string OBJECTTYPE = this.txtOBJECTTYPE.Text;
            string ATTACHNAME = this.txtATTACHNAME.Text;
            string ATTACHURL = this.txtATTACHURL.Text;
            string ATTACHTYPE = this.txtATTACHTYPE.Text;
            byte[] ATTACHBYTES = new UnicodeEncoding().GetBytes(this.txtATTACHBYTES.Text);
            decimal ATTACHSIZE = decimal.Parse(this.txtATTACHSIZE.Text);
            DateTime UPLOADTIME = DateTime.Parse(this.txtUPLOADTIME.Text);


            FUJIANModel model = new FUJIANModel();
            model.ID = ID;
            model.ATTACHID = ATTACHID;
            model.OBJECTID = OBJECTID;
            model.OBJECTTYPE = OBJECTTYPE;
            model.ATTACHNAME = ATTACHNAME;
            model.ATTACHURL = ATTACHURL;
            model.ATTACHTYPE = ATTACHTYPE;
            model.ATTACHBYTES = ATTACHBYTES;
            model.ATTACHSIZE = ATTACHSIZE;
            model.UPLOADTIME = UPLOADTIME;

            FUJIANBLL bll = new FUJIANBLL();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
